package top.techqi.usbd.desc

class StringDesc(
    bLength: Byte,
    vararg val bString: Byte
) : AbstractDesc(bLength, TYPE) {
    val string: String
        get() = String(bString, Charsets.UTF_16LE)

    constructor(bytes: ByteArray) : this(
        bytes[0],
        *bytes.sliceArray(2..<bytes[0])
    ) {
        require(bytes[1] == TYPE) {
            "Invalid type: ${bytes[1]}"
        }
    }

    companion object {
        const val TYPE: Byte = 0x03
    }
}
